package com.shunlin.paopaoku.map;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.shunlin.paopaoku.box2d.*;

public class GameMap {
    protected static String mapName;

    public static OrthographicCamera mapCamera; //设置绘制地图的相机
    public static TiledMap map; //地图
    public static OrthogonalTiledMapRenderer mapRender; //地图渲染器

    public GameMap(String mapName) {
        this.mapName = mapName;
    }

    public void drawMap() { //绘制地图的逻辑
        map = new TmxMapLoader().load(mapName);
        mapCamera = new OrthographicCamera();
        mapRender = new OrthogonalTiledMapRenderer(map);

        mapCamera.setToOrtho(false, Box2DVars.width / 2, Box2DVars.height / 2); //设置地图的视点为屏幕的中心
        mapRender.setView(mapCamera); //设置地图渲染器的矩阵
    }

    public void renderMap() {
        mapCamera.update();
        mapRender.render();
    }
}
